package com.zone.sdk.common.http;


import com.zone.sdk.common.http.executor.JobExecutor;
import com.zone.sdk.common.http.executor.PostExecutionThread;
import com.zone.sdk.common.http.executor.ThreadExecutor;
import com.zone.sdk.common.http.executor.UIThread;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

public class ObservableService {
    protected ThreadExecutor threadExecutor;
    protected PostExecutionThread postExecutionThread;

    public static ObservableService getInstance() {
        return ObservableServiceHolder.instance;
    }

    private ObservableService() {
        threadExecutor = new JobExecutor();
        postExecutionThread = new UIThread();
    }

    private static class ObservableServiceHolder {
        public static final ObservableService instance = new ObservableService();
    }

    public void execute(Observable observable, DisposableObserver observer) {
        Disposable disposable = (Disposable) observable
                .subscribeOn(Schedulers.from(threadExecutor))
                .observeOn(postExecutionThread.getScheduler())
                .subscribeWith(observer);
    }

    public void clear(){
    }
}
